package com.ruoyi.environment.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.environment.domain.OpmEnvCompyAssess;
import com.ruoyi.environment.domain.OpmEnvRule;
import com.ruoyi.environment.mapper.OpmEnvCompyAssessMapper;
import com.ruoyi.environment.service.IOpmEnvCompyAssessService;
import com.ruoyi.system.api.LinkFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 企业环评资料Service业务层处理
 *
 * @author zmc
 * @date 2021-07-23
 */
@Service
public class OpmEnvCompyAssessServiceImpl extends LinkFileServiceImpl implements IOpmEnvCompyAssessService {
    @Autowired
    private OpmEnvCompyAssessMapper opmEnvCompyAssessMapper;

    /**
     * 查询企业环评资料
     *
     * @param id 企业环评资料ID
     * @return 企业环评资料
     */
    @Override
    public OpmEnvCompyAssess selectOpmEnvCompyAssessById(Long id) {
        OpmEnvCompyAssess result = opmEnvCompyAssessMapper.selectOpmEnvCompyAssessById(id);
        result.setFileList(getFileList(id.toString()));
        return result;
    }

    /**
     * 查询企业环评资料列表
     *
     * @param opmEnvCompyAssess 企业环评资料
     * @return 企业环评资料
     */
    @Override
    public List<OpmEnvCompyAssess> selectOpmEnvCompyAssessList(OpmEnvCompyAssess opmEnvCompyAssess) {
        return opmEnvCompyAssessMapper.selectOpmEnvCompyAssessList(opmEnvCompyAssess);
    }

    /**
     * 新增企业环评资料
     *
     * @param opmEnvCompyAssess 企业环评资料
     * @return 结果
     */
    @Override
    public int insertOpmEnvCompyAssess(OpmEnvCompyAssess opmEnvCompyAssess) {
        opmEnvCompyAssess.setId(IdUtil.getSnowflake(0, 0).nextId());
        opmEnvCompyAssess.setCreateTime(DateUtils.getNowDate());
        opmEnvCompyAssess.setCreateBy(SecurityUtils.getUsername());
        linkFile(opmEnvCompyAssess.getFileIdList(), opmEnvCompyAssess.getId().toString());
        return opmEnvCompyAssessMapper.insertOpmEnvCompyAssess(opmEnvCompyAssess);
    }

    /**
     * 修改企业环评资料
     *
     * @param opmEnvCompyAssess 企业环评资料
     * @return 结果
     */
    @Override
    public int updateOpmEnvCompyAssess(OpmEnvCompyAssess opmEnvCompyAssess) {
        opmEnvCompyAssess.setUpdateTime(DateUtils.getNowDate());
        opmEnvCompyAssess.setUpdateBy(SecurityUtils.getUsername());
        linkFile(opmEnvCompyAssess.getFileIdList(),Long.toString(opmEnvCompyAssess.getId()));
        return opmEnvCompyAssessMapper.updateOpmEnvCompyAssess(opmEnvCompyAssess);
    }

    /**
     * 批量删除企业环评资料
     *
     * @param ids 需要删除的企业环评资料ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvCompyAssessByIds(Long[] ids) {
        String[] res = new String[ids.length];
        for(int i=0;i<ids.length;i++){
            res[i] = String.valueOf(ids[i]);
        }
        deleteLinkFile(res);
        return opmEnvCompyAssessMapper.deleteOpmEnvCompyAssessByIds(ids);
    }

    /**
     * 删除企业环评资料信息
     *
     * @param id 企业环评资料ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvCompyAssessById(Long id) {
        return opmEnvCompyAssessMapper.deleteOpmEnvCompyAssessById(id);
    }
}
